package persistent.prestige.console.mysql;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import persistent.prestige.console.mysql.cmd.MysqlCmd;
import persistent.prestige.console.mysql.cmd.SelectQueryCmd;
import persistent.prestige.console.mysql.connection.Connection;


public class MysqlClient {
	
	private Map<Integer, Connection> connMap = new HashMap<Integer, Connection>();
	
	private AtomicInteger seq = new AtomicInteger(1);
	
	
	
	public static final String MYSQL_HOST = "10.2.35.23";
	public static final String DB = "demo";
	public static final String USERNAME = "peter";
	public static final String PWD = "peter";
	public static final String TEST_SELECT_CMD = "select * from dw_ins limit 10";
	public static final String TEST_EXECUTE_PROCUDURE = "call dw_multi()";//调用存储过程
	public static final int MYSQL_PORT = 3306;
	
	

	
	
	/**
	 * mysql client 统一指定测试命令
	 * @param conn
	 * @return
	 */
	public static MysqlCmd getTestTask(Connection conn) {
		
		/**
		 * 测试 select 语句  == start 
		 */
		SelectQueryCmd cmd = new SelectQueryCmd(MysqlClient.TEST_SELECT_CMD, conn.getSeq());
		return cmd;
		// 测试 select 语句  == end
		
		
		/**
		 * 测试 调用存储过程
		 */
//		SelectQueryCmd cmd = new SelectQueryCmd(TEST_EXECUTE_PROCUDURE, conn.getSeq());
//		return cmd;
		
		
//		String sql = "INSERT INTO `es_seller` (`id`, `name`, `default_imgurl`, `location_name`, `location_x`, `location_y`, `trading_amount`, `account`, `user_id`, `phone`, `mobile`, `connectName`, `connectAddress`, `keyword`, `trading_count`, `creator`, `create_time`, `deleted_flag`, `status`, `across_flag`, `tag_type`, `email`, `logistics`, `check_goods_remind`, `min_eval_fee_std`, `carriage`, `logistics_rule`, `receive_time`, `logistics_type`, `delivery_time`, `business_license_img_key`, `work_week_st`, `work_week_ed`, `work_hour_st`, `work_hour_ed`, `work_status`, `seller_tese`) VALUES (24, '品珍鲜活广雅店', 'FqhQzsH_s4iwDqrALrDYvcr1dvFG', '广州雅居乐花园', 1.0000000000, 1.0000000000, 0.00, '100001', 105, '13928203121', '13928203121', '梁慧珊', '广东省广州市', '', 0, 7, '2015-12-18 17:47:30', 0, 1, 1, 1, '1', '17点前付款,预计2小时内送达', '仅支持收货后24小时内质量问题退换货申请', 0, 0, '', 1440, 2, 30, NULL, NULL, NULL, NULL, NULL, NULL, NULL);";
		
	}
	
	
	public Connection newConnection() {
		Connection conn = new Connection(MYSQL_HOST, MYSQL_PORT);
		conn.setConnectionId(seq.getAndAdd(1));
		connMap.put(conn.getConnectionId(), conn);
		
		(new Thread(conn)).start();
		return conn;
	}
	
	public static void main(String[] args) {
		MysqlClient client = new MysqlClient();
		client.newConnection();
	}
	
}
